/*
 ============================================================================
 Name		: allegrosbAppView.cpp
 Author	  : 
 Copyright   : Your copyright notice
 Description : Application view implementation
 ============================================================================
 */

// INCLUDE FILES
#include <coemain.h>
#include "allegrosbAppView.h"
#include <fbs.h>

// ============================ MEMBER FUNCTIONS ===============================

// -----------------------------------------------------------------------------
// CallegrosbAppView::NewL()
// Two-phased constructor.
// -----------------------------------------------------------------------------
//
CallegrosbAppView* CallegrosbAppView::NewL(const TRect& aRect)
	{
	CallegrosbAppView* self = CallegrosbAppView::NewLC(aRect);
	CleanupStack::Pop(self);
	return self;
	}

// -----------------------------------------------------------------------------
// CallegrosbAppView::NewLC()
// Two-phased constructor.
// -----------------------------------------------------------------------------
//
CallegrosbAppView* CallegrosbAppView::NewLC(const TRect& aRect)
	{
	CallegrosbAppView* self = new (ELeave) CallegrosbAppView;
	CleanupStack::PushL(self);
	self->ConstructL(aRect);
	return self;
	}

// -----------------------------------------------------------------------------
// CallegrosbAppView::ConstructL()
// Symbian 2nd phase constructor can leave.
// -----------------------------------------------------------------------------
//
void CallegrosbAppView::ConstructL(const TRect& aRect)
	{
	// Create a window for this application view
	bufferBitmap = new CFbsBitmap();
	bufferBitmap->Create(TSize(320, 240), EColor64K);
	CreateWindowL();

	// Set the windows size
	SetRect(aRect);

	// Activate the window, which makes it ready to be drawn
	ActivateL();
	}

// -----------------------------------------------------------------------------
// CallegrosbAppView::CallegrosbAppView()
// C++ default constructor can NOT contain any code, that might leave.
// -----------------------------------------------------------------------------
//
CallegrosbAppView::CallegrosbAppView()
	{
	// No implementation required
	}

// -----------------------------------------------------------------------------
// CallegrosbAppView::~CallegrosbAppView()
// Destructor.
// -----------------------------------------------------------------------------
//
CallegrosbAppView::~CallegrosbAppView()
	{
	// No implementation required
	}

void CallegrosbAppView::draw_to_native(unsigned char* data, int w, int h)
	{
	bufferBitmap->LockHeap();
	unsigned char* pdest = (unsigned char*)bufferBitmap->DataAddress();
	memcpy(pdest, data, w*h*2);
	bufferBitmap->UnlockHeap();
	DrawNow();
	}

// -----------------------------------------------------------------------------
// CallegrosbAppView::Draw()
// Draws the display.
// -----------------------------------------------------------------------------
//
void CallegrosbAppView::Draw(const TRect& /*aRect*/) const
	{
	// Get the standard graphics context
	CWindowGc& gc = SystemGc();
	
	// Gets the control's extent
	TRect drawRect(Rect());
	
	// Clears the screen
	gc.Clear(drawRect);
	gc.BitBlt(TPoint(0, 0), bufferBitmap);

	}

// -----------------------------------------------------------------------------
// CallegrosbAppView::SizeChanged()
// Called by framework when the view size is changed.
// -----------------------------------------------------------------------------
//
void CallegrosbAppView::SizeChanged()
	{
	DrawNow();
	}

// -----------------------------------------------------------------------------
// CallegrosbAppView::HandlePointerEventL()
// Called by framework to handle pointer touch events.
// Note: although this method is compatible with earlier SDKs, 
// it will not be called in SDKs without Touch support.
// -----------------------------------------------------------------------------
//
void CallegrosbAppView::HandlePointerEventL(const TPointerEvent& aPointerEvent)
	{

	// Call base class HandlePointerEventL()
	CCoeControl::HandlePointerEventL(aPointerEvent);
	}

// End of File
